<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
        <meta name="description" content="">
        <meta name="author" content="">
        <link rel="icon" href="../img/asset-favico.ico">
        <title>编辑信息</title>
        <link rel="stylesheet" href="../css/page-health-orderInfo.css" />
        <link rel="stylesheet" href="../plugins/elementui/index.css" />
        <script src="../plugins/jquery/dist/jquery.min.js"></script>
        <script src="../plugins/healthmobile.js"></script>
        <script src="../plugins/datapicker/datePicker.js"></script>
        <script src="../plugins/vue/vue.js"></script>
        <script src="../plugins/vue/axios-0.18.0.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script>
            var id = getUrlParam("id");//从URL地址栏获取体检套餐id
        </script>
    </head>
    <body data-spy="scroll" data-target="#myNavbar" data-offset="150">
        <div id="app" class="app">
            <!-- 页面头部 -->
            <div class="top-header">
                <span class="f-left"><i class="icon-back" onclick="history.go(-1)"></i></span>
                <span class="center">传智健康</span>
                <span class="f-right"><i class="icon-more"></i></span>
            </div>
            <!-- 页面内容 -->
            <div class="contentBox">
                <div class="card">
                    <div class="project-know">
                        <a href="orderNotice.html" class="link-page">
                            <i class="icon-ask-circle"><span class="path1"></span><span class="path2"></span></i>
                            <span class="word"></span>
                            <span class="arrow"><i class="icon-rit-arrow"></i></span>
                        </a>
                    </div>
                </div>
                <div class="form-info">
                    <div class="info-title">
                        <span class="name">换绑手机</span>
                    </div>
                    <form class="info-form">
                        <div class="input-row">
                            <label>手机号</label>
                                <input v-model="telephone" id='account' type="text" placeholder="请输入手机号">
                                <input id="validateCodeButton" @click="sendValidateCode()" type="button" style="font-size: 12px" value="获取验证码">
                        </div>
                        <div class="input-row">
                            <label>验证码</label>
                                <input v-model="loginInfo.validateCode" style="width:80%" id='phone' type="text" placeholder="请输入验证码">
                        </div>
                        <div class="input-row">
                            <label>新手机号</label>
                            <input v-model="loginInfo.telephone" type="text" class="input-clear" placeholder="请确认新密码">
                        </div>
                    </form>
                    <div class="box-button">
                        <button id="submit" @click="edit2Telephone()" type="button" class="btn order-btn">确定</button>
                    </div>
                </div>
            </div>
        </div>
        <script>
            var vue = new Vue({
                el:'#app',
                data:{
                    originTelephone:'',//原始手机号
                    telephone:'',//用户输入的手机号
                    loginInfo:{
                        id:id,
                        telephone:'',//要修改的手机号
                        validateCode:''//验证码
                    }
                },
                methods:{
                    //发送验证码
                    sendValidateCode(){
                        var telephone = this.telephone;
                        if (!checkTelephone(telephone)) {
                            this.$message.error('请输入正确的手机号');
                            return false;
                        }
                        if (this.telephone != this.originTelephone) {
                            this.$message.error('请输入注册时的手机号');
                            return false;
                        }
                        validateCodeButton = $("#validateCodeButton")[0];
                        clock = window.setInterval(doLoop, 1000); //一秒执行一次
                        axios.post("/validateCode/send4ChangePhone.do?telephone=" + this.originTelephone).then((response) => {
                            if(!response.data.flag){
                                //验证码发送失败
                                this.$message.error('验证码发送失败，请检查手机号输入是否正确');
                            }else {
                                this.$message.success("验证码发送成功");
                            }
                        });
                    },
                    edit2Telephone(){
                        if (!checkTelephone(this.loginInfo.telephone)) {
                            this.$message.error('请输入正确的手机号');
                            return false;
                        }
                        if (this.telephone != this.originTelephone) {
                            this.$message.error('请输入注册时的手机号');
                            return false;
                        }
                        axios.post("/member/edit2Telephone.do",this.loginInfo).then((res)=>{
                            if (res.data.flag) {
                                this.$message.success("修改手机号成功");
                                window.location.href="/pages/login.html";
                            }else {
                                this.$message.error("修改手机号失败");
                            }
                        });
                    }
                },
                mounted(){
                    //根据id查询手机号,//校验手机号输入是否正确
                    axios.get("/member/findMemberById.do?id="+id).then((rep)=>{
                        if (rep.data.flag) {
                            this.originTelephone=rep.data.data.phoneNumber;
                        }
                    });
                }
            });
        </script>
    </body>
</html>